package com.example.zyz.demo_sql_grid_list_notification_dialog;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.sql.Array;
import java.util.ArrayList;
import java.util.Map;

/**
 * Created by zyz on 15/11/17.
 */
public class listviewactivity extends AppCompatActivity {
    private ListView listv;
    private ArrayAdapter<String>listviewadapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_listview);

        open_new_db opendb=new open_new_db(listviewactivity.this,"sqltest.db",null,1);
        SQLiteDatabase db=opendb.getWritableDatabase();
        Cursor c= db.rawQuery("select * from stutb", null);
        String [] data=c.getColumnNames();
        listv= (ListView) findViewById(R.id.listView);
        ArrayList array=new ArrayList<String>();

        if (c!=null)
        {
            String[] cols=c.getColumnNames();
            while(c.moveToNext())
            {
                for (String ColumnName:cols)
                {
                    Log.i("info",ColumnName+":"+c.getString(c.getColumnIndex(ColumnName)));
                }
                String s="id："+c.getString(0)+ " 姓名："+c.getString(1)+" 年龄："+c.getString(3)+" 性别："+c.getString(2)+" ";
                array.add(s);
            }
            c.close();
        }
        db.close();
        listviewadapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,array);
        listv.setAdapter(listviewadapter);
    }


}
